export class ResponseUtil {
  public static async success(data: Partial<ApiTypes.ApiBaseResult>): Promise<ApiTypes.ApiBaseResult> {
    const base: ApiTypes.ApiBaseResult = {
      code: 0,
      success: true,
      data: {},
      message: 'ok'
    }
    const result = Object.assign(base, data)
    return Promise.resolve(result)
  }

  public static async fail(code: number, msg: string): Promise<ApiTypes.ApiBaseResult> {
    const base: ApiTypes.ApiBaseResult = {
      code,
      success: true,
      data: {},
      message: msg
    }
    return Promise.resolve(base)
  }

  public static async authError(): Promise<ApiTypes.ApiBaseResult> {
    const base: ApiTypes.ApiBaseResult = {
      code: 403,
      success: true,
      data: {},
      message: 'token 无效'
    }
    return Promise.resolve(base)
  }

  public static async serverError(): Promise<ApiTypes.ApiBaseResult> {
    const base: ApiTypes.ApiBaseResult = {
      code: 500,
      success: true,
      data: {},
      message: 'server error'
    }
    return Promise.resolve(base)
  }
}
